package com.newbingo.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.newbingo.dao.imple.IGameDao;
import com.newbingo.dto.imple.IGameDto;
import com.newbingo.entity.Game;
import com.newbingo.entity.GameTable;

public class GameDto implements Serializable, IGameDto {
	private IGameDao gameDao;
	private Integer gameno;
	private String gamename;
	private String type;
	private String rule;
	private List<GameTableDto> gameTableDtos = new ArrayList<GameTableDto>();

	/*
	 * 查询所有的游戏，进行DTO转换
	 */
	public List<GameDto> findAllGames() {
		List<GameDto> gameDtos = new ArrayList<GameDto>();
		List<Game> games = gameDao.findAll();
		if (games != null && games.size() > 0) {
			// 游戏进行DTO化
			for (Game game : games) {
				GameDto gameDto = changeToDto(game);
				Set<GameTable> gameTables = game.getGtable();
				if (gameTables != null && gameTables.size() > 0) {
					// 游戏桌进行DTO化
					for (GameTable gameTable : gameTables) {
						GameTableDto gameTableDto = new GameTableDto();
						gameDto.getGameTableDtos().add(
								gameTableDto.changeToDto(gameTable));
					}
				}
				gameDtos.add(gameDto);
			}
		}
		return gameDtos;
	}

	/*
	 * Game Entity进行DTO对象转换
	 */
	public GameDto changeToDto(Game game) {
		GameDto dto = new GameDto();
		dto.setGameno(game.getGameno());
		dto.setGamename(game.getGamename());
		dto.setType(game.getType());
		dto.setRule(game.getRule());
		return dto;
	}

	public IGameDao getGameDao() {
		return gameDao;
	}

	public void setGameDao(IGameDao gameDao) {
		this.gameDao = gameDao;
	}

	public Integer getGameno() {
		return gameno;
	}

	public void setGameno(Integer gameno) {
		this.gameno = gameno;
	}

	public String getGamename() {
		return gamename;
	}

	public void setGamename(String gamename) {
		this.gamename = gamename;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getRule() {
		return rule;
	}

	public void setRule(String rule) {
		this.rule = rule;
	}

	public List<GameTableDto> getGameTableDtos() {
		return gameTableDtos;
	}

	public void setGameTableDtos(List<GameTableDto> gameTableDtos) {
		this.gameTableDtos = gameTableDtos;
	}

}
